package jwei.apps.zappos;

import java.util.List;

import jwei.apps.helpers.ConnectionManager;
import jwei.apps.helpers.GetMethods;
import jwei.apps.json.JsonToStyle;
import jwei.apps.objects.APIConstants;
import jwei.apps.objects.Style;

import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class ZapposSearchSimilar {

    private static DefaultHttpClient httpClient = ConnectionManager.getClient();

    public static List<Style> searchSimilarStyles(long styleId) {
        String url = String.format(APIConstants.SIMILARITY, styleId);
        String response = GetMethods.doGetWithResponse(url, httpClient);
        if (!response.equals("")) {
            try {
                JSONObject jsonResponse = new JSONObject(response);
                JSONArray results = jsonResponse.getJSONArray("results");
                List<Style> ret = JsonToStyle.convertToStyles(results);
                return ret;
            } catch (JSONException e) {
                e.printStackTrace();
                return null;
            }
        } else {
            System.out.println(ZapposSearchSimilar.class.getCanonicalName() + ": Did not retrieve response");
            return null;
        }
    }

}
